package com.tianji.aigc.tools;

import com.tianji.aigc.constants.ToolConstants;
import com.tianji.aigc.entity.CourseInfo;
import com.tianji.aigc.result.ToolResultHolder;
import com.tianji.api.client.course.CourseClient;
import com.tianji.api.dto.course.CourseBaseInfoDTO;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CourseTool {
    @Autowired
    private CourseClient courseClient;



    @Tool(description = ToolConstants.Tool.QUERY_COURSE_BY_ID)
    public CourseInfo qureyCourseById( @ToolParam(description = ToolConstants.Tool_Param.COURSE_ID) Long id,ToolContext toolContext){


        CourseBaseInfoDTO courseBaseInfoDTO = courseClient.baseInfo(id, true);

        CourseInfo courseInfo = CourseInfo.of(courseBaseInfoDTO);
        //获取大map的Id
        String  requestId = (String) toolContext.getContext().get("request_id");
        //封装小map的Id
        String field="courseInfo_"+id;
        //将数据封装成大map
        ToolResultHolder.put(requestId,field,courseInfo);
        return courseInfo;
    }
}
